﻿using System;
using System.Collections.Generic;
using System.Text;
using AgencyManagerSystem.Model;
using AgencyManagerSystem.DataUpdater;
using AgencyManagerSystem.Common;
using AgencyManagerSystem.DataFetcher;

namespace AgencyManagerSystem.Core
{
    public class ModuleUpdaterCreator : BaseUpdaterCreator<ModuleModel>
    {
        public ModuleUpdater CreateModuleUpdaterInstance()
        {
            ModuleUpdater moduleUpdater = new ModuleUpdater(new ModuleFetcher());
            moduleUpdater.DataUpdating += FlagAndApproveFlagValid;
            moduleUpdater.DataUpdating += ModuleNotSpace;
            return moduleUpdater;
        }

        private void ModuleNotSpace(BaseUpdater<ModuleModel> sender, DataUpdatingEventArgs<ModuleModel> e)
        {
            if (e.Insert == null)
                return;
            if(String.IsNullOrWhiteSpace(e.Insert.Name)|| String.IsNullOrWhiteSpace(e.Insert.Code))
            {
                LogHelper.Log(this.GetType().Name, String.Format("MODULENOTSPACE:模块检查不通过", e.Insert.AutoId));
                e.Message = "编号/名称不能为空";
                e.Cancel = true ;
            }
        }
    }
}

